package com.itrus.spring.transaction.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;

@Service
@EnableTransactionManagement
public class FirstService {

    @Autowired
    private SecondService secondService;


    @Transactional(rollbackFor = Exception.class)
    public void execute() {
        try {
            boolean synchronizationActive = TransactionSynchronizationManager.isSynchronizationActive();
            System.out.println("FirstService synchronizationActive:" + synchronizationActive);
            secondService.execute();
        } catch (Exception e) {
            System.out.println("erro r" + e);
        }
    }
}